#include<iostream>
#include<memory.h>
#include<string>
using namespace std;

void setZeros(int **matrix,int m,int n)
{
	int row[m],column[n];
	memset(row,0,sizeof(row));
	memset(column,0,sizeof(column));
	//store the row and column index with value 0
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if( *((int*)matrix+n*i+j) == 0 )// matrix[i][j]==0
			{
				row[i]=1;
				column[j]=1;
			}
		}
	}
	//set arr[i][j] to 0 if either row i or column j has a 0
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
		{
			if( row[i]==1 || column[j]==1  )
			{
				*((int*)matrix+n*i+j)=0;//matrix[i][j]=0;
			}
		}
	}
}

void display(int **matrix , int m ,int n)
{
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<n;j++)
			cout<<*((int*)matrix+n*i+j)<<" ";
		cout<<endl;
	}
}

int main()
{
	int a[3][4]=
	{
		{0,1,1,0},
		{1,1,1,1},
		{0,1,0,1}
	};
	setZeros((int**)a,3,4);
	cout<<"a:"<<endl;
	display((int**)a,3,4);
	
	int b[5][4]=
	{
		{1,0,1,0},
		{0,1,1,0},
		{0,0,1,1},
		{1,0,1,1},
		{1,1,1,1}
	};
	setZeros((int**)b,5,4);
	cout<<"b:"<<endl;
	display((int**)b,5,4);

	return 0;
}

